package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.StudentsForm;

public class ResidencyAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		String residency = request.getParameter("residency");
		
		// Cast the form
		StudentsForm iForm = (StudentsForm) form;
					
		iForm.setResidency(residency);
	
		RowSet crsUniversities = null;
		try {
			crsUniversities = StudentModel.getUnivercities();
		} catch (DbException e) {
			e.printStackTrace();
		}
		
		// Store the RowSet in the request scope
		request.setAttribute("crsUniversities", crsUniversities);
				
		return mapping.findForward("success");
	}
}